<?php 
$connection = Yii::app()->db;

$oDeporte = DeporteActividad::model()->findByPk($deporte);
echo "<h1>";
?>
<img align="middle" alt="<?php echo $oDeporte->deporte_actividad_observacion; ?>"  src="<?php echo Yii::app()->theme->baseUrl.'/images/'.strtolower($oDeporte->deporte_actividad_observacion).'.png'; ?>" />
<?php 
echo "MEDALLERO DE ".strtoupper($oDeporte->deporte_actividad_descripcion)."</h1>";
?>	
<table id="medallero">
<thead>
<tr>
	<th scope="col">PUESTO</th>
	<th scope="col">CON</th>
	<th scope="col">ORO</th>
	<th scope="col">PLATA</th>
	<th scope="col">BRONCE</th>
	<th scope="col">MEDALLAS TOTALES</th>		
</tr>
</thead>
<tbody>
<?php
foreach ($orden as $pais)
{
	
		$command = $connection->createCommand("
		SELECT gp.pais_id,gp.pais_nombre,sum(grm.grid_oro) as oro,sum(grm.grid_plata) as plata,sum(grm.grid_bronce) as bronce
		    FROM grid_r_medallas grm 
        
        inner join grid_r_entidad gre 
        on gre.grid_entidad_id = grm.grid_entidad_id
        
        inner join grid_pais gp
        on gp.pais_id = gre.grid_pais_id
                    
        where gre.grid_deporte_actividad_id=$deporte and gp.pais_id=".$pais->pais_id."
        
        group by pais_id,pais_nombre");

		$dataReader = $command->query();
		
		$row=$dataReader->read();
			
		?>
		<tr>
			<td align="center"><?php echo $pais->orden?></td>
			
			<td >
		<img align="middle" alt="<?php echo $row['pais_nombre']; ?>"  src="<?php echo Yii::app()->theme->baseUrl.'/images/'.substr(strtolower($row['pais_nombre']),0,3).'.png'; ?>" />	
		<?php echo $row['pais_nombre']?></td>							
			
			<td align="center"><?php if($row['oro']!='')
						echo $row['oro'];
						else echo '0'; ?></td>
			
			<td align="center"><?php if($row['plata']!='')
						echo $row['plata'];
						else echo '0'; ?></td>
			
			<td align="center"><?php if($row['bronce']!='')
						echo $row['bronce'];
						else echo '0'; ?></td>
				
			<td align="center"><?php echo $row['oro']+$row['plata']+$row['bronce']?></td>	
		</tr>		
<?php 	
	
}
?>
</tbody>
</table>